package com.scorpio.common.core.domain;

import com.scorpio.common.constant.AppHttpStatus;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;

    private String msg;

    private T data;

    private Result() {

    }

    /**
     * 返回成功消息
     *
     * @return 成功消息
     */
    public static Result success() {
        Result result = new Result();
        result.code = AppHttpStatus.SUCCESS;
        return result;
    }

    /**
     * 返回成功数据
     *
     * @return 成功消息
     */
    public static <T> Result<T> success(T data) {
        Result<T> result = new Result();
        result.code = AppHttpStatus.SUCCESS;
        result.data = data;
        return result;
    }

    /**
     * 返回成功消息
     *
     * @param msg 返回内容
     * @return 成功消息
     */
    public static <T> Result<T> success(T data, String msg) {
        Result<T> result = new Result();
        result.code = AppHttpStatus.SUCCESS;
        result.msg = msg;
        result.data = data;
        return result;
    }


    /**
     * 返回错误消息
     *
     * @return
     */
    public static Result error() {
        Result result = new Result();
        result.code = AppHttpStatus.ERROR;
        result.msg = "操作失败";
        return result;
    }

    /**
     * 返回错误消息
     *
     * @param msg 返回内容
     * @return 警告消息
     */
    public static Result error(String msg) {
        Result result = new Result();
        result.code = AppHttpStatus.ERROR;
        result.msg = msg;
        return result;
    }

    /**
     * 返回错误消息
     *
     * @param code
     * @param msg  警告消息
     * @return 警告消息
     */
    public static Result error(int code, String msg) {
        Result result = new Result();
        result.code = code;
        result.msg = msg;
        return result;
    }

}
